package com.xuetang9.fujian.socketdemo.tcpdemo.onetomore;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author: fujian
 * @description: TCP编程 服务端
 * @date: 2021/5/10 9:04
 * @version: V1.0
 * @package: com.xuetang9.fujian.socketdemo.tcpdemo.onetomore
 **/
public class AIServer {
    private static final int port = 9527;

    private ServerSocket serverSocket;
    private boolean isRunning;

    public AIServer(){
        this.isRunning = true;
    }

    public void start(){
        try {
            serverSocket = new ServerSocket(port);
            System.out.println("服务端已启动，监听端口L:" + port);
            while (isRunning){
                Socket socket = serverSocket.accept();
                System.out.println("客户端：" + socket.getRemoteSocketAddress() + "已连接成功");
                new Thread(new SocketHandler(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new AIServer().start();
    }
}
